
/**
** \file       ast.h
**
** \brief      this file contains the structure and fonctions declarations
**             about the Abstract Syntax Tree (AST) built during the parsing.
**             The AST built will be the base of the execution part.
**             The AST will be given to a function that executes it: it means
**             that the AST will be modified until he becomes a single string
**             which will be returned on the standard output.
**             For instance, the node which represents structure "if" has 3
**             sons but can be replaced by a single node after an if function
**             executes.
**
** \authors    Ben M'rad Hanna, Boillot Ulysse, De Oliveira Guillaume,
**             Laterem Hamza and Nguyen Viet Dung worked on this part of the
**             42sh project.
**
** \version    0.8
**
** \date       13 Novembre 2010
**
*/

#ifndef AST_H_
# define AST_H_

/**
** \struct     s_andor s_else_clause s_cmpdlist s_word s_caseitem s_caseclause
**             s_rulecase s_dogroup s_rulefor s_ruleif s_ruleuntil s_rulewhile
**             s_rulecase s_redir s_element s_prefix s_sh_cmd s_smp_cmd
**             s_funcdec s_command s_pipeline s_list s_ast
**
** \brief      All these structures are potentially a node of the AST.
**             The sons of each node is a member of the struct.
**             It must be noticed that a father of a struct which is a
**             linked list is the father of all the elements of the list.
**
*/

struct andor;

struct else_clause;

/**
** \struct    s_andor
**
** \brief      Structure for && and ||
**
*/

typedef struct andor	s_andor;

typedef struct else_clause s_else_clause;

typedef struct          cmpdlist
{
  struct andor		*andor;
}                       s_cmpdlist;

typedef struct		word
{
    char                *word;
    struct word         *next;
}			s_word;

typedef struct          caseitem
{
    s_word              *word;
    s_cmpdlist          *cmpdlist;
    struct caseitem     *next;
}                       s_caseitem;

typedef struct          caseclause
{
    s_caseitem          *caseitem;
}                       s_caseclause;

typedef struct          rulecase
{
    char                *in_case;
    s_caseclause        *in_in;
}                       s_rulecase;

typedef struct          dogroup
{
    s_cmpdlist          *todo;
}                       s_dogroup;

typedef struct          rulefor
{
    char                *in_for;
    s_word              *in_in;
    s_dogroup           *in_do;
}                       s_rulefor;

typedef struct          ruleif
{
    s_cmpdlist          *in_if;
    s_cmpdlist          *in_then;
    s_else_clause       *else_clause;
}                       s_ruleif;

typedef struct          ruleuntil
{
    s_cmpdlist          *in_until;
    s_dogroup           *in_do;
}                       s_ruleuntil;

struct			else_clause
{
    s_cmpdlist          *in_if;
    s_cmpdlist          *in_then;
    s_cmpdlist          *in_else;
    struct else_clause  *else_clause;
};

typedef struct          rulewhile
{
    s_cmpdlist          *in_while;
    s_dogroup           *in_do;
}                       s_rulewhile;

typedef struct          redir
{
    int                 nb_io;
    char                *type;
    char                *string;
    struct redir        *next;
}                       s_redir;

typedef struct          element
{
    s_word              *word;
    s_redir             *redir;
    struct element      *next;
}                       s_element;

typedef struct          prefix
{
    char                *aw;
    s_redir             *redir;
    struct prefix       *next;
}                       s_prefix;

typedef struct          sh_cmd
{
    s_redir             *redir;
    s_cmpdlist          *cmpdlist;
    s_rulefor           *rulefor;
    s_ruleif            *ruleif;
    s_ruleuntil         *ruleuntil;
    s_rulecase          *rulecase;
    s_rulewhile         *rulewhile;
}                       s_sh_cmd;

typedef struct          funcdec
{
    s_redir             *redir;
    char                *function;
    char                *word;
    s_sh_cmd            *sh_cmd;
}                       s_funcdec;

typedef struct          smp_cmd
{
    s_prefix            *prefix;
    s_element           *elt;
}                       s_smp_cmd;

typedef struct          command
{
    s_smp_cmd           *smp_cmd;
    s_sh_cmd            *sh_cmd;
    s_funcdec           *funcdec;
    struct command      *next;
}                       s_command;

typedef struct          pipeline
{
    struct pipeline     *next;
    char                *no;
    s_command           *cmd;
}                       s_pipeline;

struct		        andor
{
    struct andor        *next;
    s_pipeline          *pl;
    char                *and_or;
};

typedef struct          list
{
    struct andor        *andor;
}                       s_list;

typedef struct          ast
{
    s_list              *list;
}                       s_ast;

#endif /* !AST_H_ */
